package com.elvish.efast.api.system;

import com.alibaba.dubbo.config.annotation.Reference;
import com.elvish.efast.api.base.BaseApi;
import com.elvish.efast.common.entity.Result;
import com.elvish.efast.common.utils.ResultUtil;
import com.elvish.efast.model.entity.Menu;
import com.elvish.efast.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author elvish
 * @date 2018/11/1 14:44
 * @blog oschina(https : / / my.oschina.net / xiaozhutefannao)
 */
@Component
@RequestMapping
@Slf4j
public class LoginApi extends BaseApi {

    @Reference
    private MenuService menuService;

    @RequestMapping("/login")
    @ResponseBody
    public Result login(String username, String password) {
        log.info("username：" + username);
        log.info("password：" + password);
        return ResultUtil.success();
    }


    @RequestMapping("/index")
    public String index(Model model) {
        List<Menu> menus = menuService.getMenuTree();
        model.addAttribute("menus", menus);
        return "index";
    }


    @RequestMapping("/welcome")
    public String main() {
        return "welcome";
    }

}
